# -*- coding: utf-8 -*-
import os
import urllib

from django.utils import simplejson
from google.appengine.ext import db
from google.appengine.api import urlfetch

class YASAObj(db.Model):
  content = db.StringProperty(multiline=True)
  minLength = db.IntegerProperty()
  freqThreshold = db.IntegerProperty()
  utf8_or_ascii = db.BooleanProperty()
  def getFreq(self):
    form_fields = {
    "min": self.minLength,
    "freq": self.freqThreshold,
    'content': self.content.encode('utf-8')
    }
    form_data = urllib.urlencode(form_fields)
    result = urlfetch.fetch(url='http://yasa.newzilla.org/run/json/',
			    payload=form_data,
			    method=urlfetch.POST,
			    headers={'Content-Type': 'application/x-www-form-urlencoded'})
    resultJson = simplejson.loads(result.content)
    return resultJson


